package p2pscrabble;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class WordChecker extends JPanel implements ActionListener {
	Dictionary dict = new Dictionary();
	JTextField wordInput;
	JButton submit;
	JLabel result;

	public WordChecker() {
		wordInput = new JTextField("",15);
		submit = new JButton("Check");
		result = new JLabel();

		this.add(wordInput);
		this.add(submit);
		this.add(result);

		submit.addActionListener(this);
		submit.setActionCommand("check");
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getActionCommand().equals("check")) {
			if (wordInput.getText() == null || wordInput.getText().equals(""))
				result.setText("");
			else if (dict.checkWordExist(wordInput.getText()))
				result.setText("OK");
			else
				result.setText("NO");
		}
	}

}
